package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/27 0027 10:16
 * @version V1.0
 */
public class 统计将重叠区间合并成组的方案数_2580 {
    private static final int MOD = 1_000_000_007;

    public int countWays(int[][] ranges) {
        Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));
        int res = 2;
        int end = ranges[0][1];
        for (int i = 1; i < ranges.length; i++) {
            int[] range = ranges[i];
            int rs = range[0];
            int re = range[1];
            if (end < rs) {
                end = re;
                res = res * 2 % MOD;
            } else if (end < re) {
                end = re;
            }
        }
        return res;
    }

    @Test
    public void testCountWays () {
        int[][] ranges = {{1,3},{10,20},{2,5},{4,8}};
        System.out.println(countWays(ranges));
    }
}
